import Axios from 'axios'
import router from '@/router/index'
import Vue from "vue";

router.beforeEach((to, from, next) => {


    document.title = "智慧校园管理系统";


//如果是“登录”路由，不做操作
    if (to.path === '/login') {
        return  next()
    }
    //获取路由规则
    const routes = router.getRoutes();
    //映射出path
    const pathList = routes.map(item => item.path)
    //判断是否是非法路由,如果是跳转404页面
    if (pathList.indexOf(to.path) === -1) {
        return  next({path: "/notFindPage", replace: true})
    }

    // const loginStatus = sessionStorage.getItem("loginStatus")
    const loginStatus = window.localStorage.getItem("loginStatus")
    //判断是否登录成功
    if (loginStatus === 'success') {
        return  next()
    } else {
        Vue.prototype.$message.error("请先登录后，再操作！")
        return next("/login")


    }


})

router.afterEach(() => {
    // finish progress bar
    // NProgress.done()
})